﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Chat
{
    /// <summary>
    /// Interaction logic for UserControlMessageSent.xaml
    /// </summary>
    public partial class UserControlMessageSent : UserControl, IUserControlMessage
    {
        public UserControlMessageSent(string text, DateTime time)
        {
            InitializeComponent();
            Text.Text = text;
            if (Math.Floor((DateTime.Now - time).TotalDays) == 0)
            {
                Date.Text = "今天";
            }
            else if (Math.Floor((DateTime.Now - time).TotalDays) == 1)
            {
                Date.Text = "昨天";
            }
            else if (Math.Floor((DateTime.Now - time).TotalDays) < 7)
            {
                Date.Text = time.DayOfWeek.ToString();
            }
            else if (time.Year == DateTime.Now.Year)
            {
                Date.Text = string.Format("{0}月{1}日", time.Month, time.Day);
            }
            else
            {
                Date.Text = string.Format("{3}年{0}月{1}日", time.Month, time.Day, time.Year);
            }
            Date.Text += string.Format(" {0}:{1}", time.Hour, time.Minute);
        }
    }
}